<?php global $has_permit; ?>
<div class="clearfix auto_height">
<div class="db_left bl">
    <?php $this->load->view('cms/article/side_block'); ?>
</div>
<div class="db_right bl">
<?php if ($has_permit) :?>
<form data-result-id="ajax_result" class="ajax_form" action="<?php echo $form_action; ?>" method="post" id="frm_comment_gridview">
<div id="ajax_result">
    <div id="breadcrumb" class="clearfix mt_10">
        <ul class="h_list no_list_style ah">
            <li><a href="<?php echo site_url('admin/dashboard', true); ?>">Bảng điều khiển</a></li>
            <li class="SecondLast"><a href="<?php echo site_url('admin/cms/comment/filtered_list/' . $return_url, true); ?>">Danh sách <?php echo $module_title; ?></a></li>
        </ul>
    </div>
    <div class="std_header auto_height">
        <div class="left">
            <strong>Quản lý danh sách bình luận</strong>
        </div>
        <div class="right">
            <button type="button" class="gray_btn" onclick="window.location='<?php echo site_url('admin/cms/comment/edit', true); ?>'">
                <span>Thêm mới</span>
            </button>
        </div>
    </div>
    <div class="std_header search_header auto_height">
        <div class="std" align="center">
            <table cellpadding="0" cellspacing="5" border="0">
                <tr>
                    <td>
                        <strong>Ngày tạo</strong>
                    </td>
                    <td>
                        <input name="filters[created_at_from]" placeholder="Từ ngày" type="text" class="std_input date_picker" value="<?php echo $filters['created_at_from']; ?>" />
                    </td>
                    <td style="pdl_10">
                        -
                    </td>
                    <td>
                        <input name="filters[created_at_to]" placeholder="Đến ngày" type="text" class="std_input date_picker" value="<?php echo $filters['created_at_to']; ?>" />
                    </td>
                    <td style="padding-left: 10px">
                        <strong>Ngày duyệt</strong>
                    </td>
                    <td>
                        <input name="filters[approved_at_from]" placeholder="Từ ngày" type="text" class="std_input date_picker" value="<?php echo $filters['approved_at_from']; ?>" />
                    </td>
                    <td style="pdl_10">
                        -
                    </td>
                    <td>
                        <input name="filters[approved_at_to]" placeholder="Đến ngày" type="text" class="std_input date_picker" value="<?php echo $filters['approved_at_to']; ?>" />
                    </td>
                </tr>
            </table>
        </div>
        <div class="std clearfix mt_10" align="center">
            <button type="button" class="gray_btn" onclick="return admin_cms_comment.act_filter()">
                <span>Tìm kiếm</span>
            </button>
            &nbsp;
            <button type="button" class="gray_btn" onclick="return admin_cms_comment.reset_filters('frm_comment_gridview')">
                <span>Xóa lọc</span>
            </button>
        </div>
    </div>
    <div id="comment_management">
        <?php $this->load->view('cms/comment/message'); ?>
        <div id="tab_list">
            <?php $paginator = $this->load->view('cms/comment/paginator', null, true); echo $paginator; ?>
            <input type="hidden" name="current_page" id="current_page" value="<?php echo $current_page; ?>" />
            <div class="block" id="lst_comment">
                <table class="gridview" width="100%" cellpadding="0" cellspacing="0" border="0">
                    <thead>
                    <tr>
                        <td><input id="check_all" type="checkbox" onclick="btn_util.check_all(this.checked, '.chk_id')" /></td>
                        <td width="30px"><b>ID</b></td>
                        <td colspan="4"><b>Bình luận</b></td>
                    </tr>
                    </thead>
                    <tbody>
                    <tr class="filters">
                        <td colspan="2">
                            <input style="width: 80px; margin: 0px auto" placeholder="ID" type="text" class="small_filter" name="filters[id][value]" title="Tìm kiếm theo id bình luận" value="<?php echo $filters['id']['value']; ?>" />
                            <input type="hidden" value="equal" name="filters[id][type]" />
                        </td>
                        <td>
                            <input placeholder="Từ khóa" type="text" class="wide_filter" name="filters[title][value]" title="Tìm kiếm theo tiêu đề bình luận" value="<?php echo $filters['title']['value']; ?>" />
                            <input type="hidden" value="text" name="filters[title][type]" />
                        </td>
                        <td>
                            <input placeholder="Email" type="text" class="wide_filter" name="filters[title][value]" title="Tìm kiếm theo tiêu đề bình luận" value="<?php echo $filters['email']['value']; ?>" />
                            <input type="hidden" value="text" name="filters[email][type]" />
                        </td>
                        <td>
                            <select name="filters[is_approved][value]" style="width: 120px">
                                <option value="-1">-- Tất cả --</option>
                                <?php foreach ($this->cms_comment_model->get_list_status() as $value => $label) :?>
                                <option <?php if (intval(get_field($filters['is_approved'], 'value')) == $value) :?>selected="selected"<?php endif; ?> value="<?php echo $value; ?>"><?php echo $label; ?></option>
                                <?php endforeach; ?>
                            </select>
                            <input type="hidden" name="filters[is_approved][type]" value="equal" />
                            <input type="hidden" name="filters[is_approved][exclude]" value="-1" />
                        </td>
                        <td width="150px" colspan="2">
                            <button class="gray_btn" type="submit">
                                <span>Lọc</span>
                            </button>
                            <button class="gray_btn" type="button" onclick="return admin_cms_comment.reset_filters('frm_comment_gridview')">
                                <span>Xóa lọc</span>
                            </button>
                        </td>
                    </tr>
                    <?php if (count($collection) != 0) : ?>
                        <?php foreach ($collection as $comment) : ?>
                        <tr>
                            <td width="30px" valign="top">
                                <input class="chk_id" type="checkbox" name="selected[]" value="<?php echo $comment->id; ?>" />
                            </td>
                            <td width="30px" valign="top">
                                <?php echo $comment->id; ?>
                            </td>
                            <td valign="top" width="100%" colspan="4">
                                <div class="bl" style="min-width: 500px">
                                    <p>
                                        <?php if ($comment->is_approved == 1) :?>
                                        <span class="icon icon_active"></span>
                                        <?php else :?>
                                        <span class="icon icon_deactive"></span>
                                        <?php endif; ?>
                                        <strong><a href="<?php echo site_url('admin/cms/comment/edit/id/' . $comment->id . '/return/' . $return_url, true); ?>"><?php echo get_field($comment, 'title'); ?></a></strong>
                                    </p>
                                    <p class="small_datetime mt_10"><span class="icon icon_author"></span>Gửi bởi <strong><a href="@mailto:<?php echo $comment->email; ?>"><?php echo $comment->name; ?></strong></a> vào lúc <?php echo date('H:i, d/m/Y', $comment->created_at); ?></p>
                                    <p class="small_datetime mt_10" style="width: 600px">
                                        <?php echo $comment->content; ?>
                                    </p>
                                    <p class="mt_10">
                                        <strong><a title="Chỉnh sửa" class="icon icon_edit" href="<?php echo site_url('admin/cms/comment/edit/id/' . $comment->id . '/return/deleted', true); ?>"></a></strong>
                                        <strong><a onclick="return confirm('Bạn muốn xóa bình luận này')" title="Xóa bình luận" class="icon icon_delete" href="<?php echo site_url('admin/cms/comment/delete/id/' . $comment->id . '/return/deleted', true); ?>"></a></strong>
                                        <strong><a onclick="return confirm('Bạn muốn duyệt bình luận này')" title="Duyệt bình luận" class="icon icon_publish" href="<?php echo site_url('admin/cms/comment/approved/id/' . $comment->id, true); ?>"></a></strong>
                                        <strong><a onclick="return confirm('Bạn muốn hủy duyệt bình luận này')" title="Hủy duyệt bình luận" class="icon icon_unpublish" href="<?php echo site_url('admin/cms/comment/disapproved/id/' . $comment->id, true); ?>"></a></strong>
                                    </p>
                                </div>
                            </td>
                        </tr>
                            <?php endforeach; ?>
                        <?php else : ?>
                        <tr>
                            <td colspan="9" style="padding: 10px">
                                <p align="center">Danh sách <?php echo $module_title; ?> là rỗng trong thời điểm này hoặc truy vấn tìm kiếm không tìm thấy kết quả, <a href="<?php echo site_url('admin/cms/comment/filtered_list/' . $return_url, true); ?>">Thử lại</a></p>
                            </td>
                        </tr>
                        <?php endif; ?>
                    </tbody>
                    <tfoot>
                    </tfoot>
                </table>
            </div>
            <?php echo $paginator; ?>
        </div>
    </div>
</div>
</form>
<?php else :?>
    <?php $this->load->view('layouts/restricted'); ?>
<?php endif; ?>
</div>
</div>

<script type="text/javascript" src="<?php echo BASE_URL; ?>js/admin/cms/comment/function.js"></script>
<script type="text/javascript">
    $(".record_per_page").val("<?php echo $record_per_page; ?>");
    $(".record_per_page").change(function() {
        var val = $(this).val();
        $(".record_per_page").val(val);
        return admin_cms_comment.act_filter();
    });
</script>